package com.atguigu.guli.service.cms.api;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.cms.entity.Ad;
import com.atguigu.guli.service.cms.service.AdService;
import com.atguigu.guli.service.cms.service.AdTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 推荐位 前端控制器
 * </p>
 *
 * @author Miluo
 * @since 2020-10-31
 */
@RestController
@Api(tags = "网页访问广告管理")
@RequestMapping("/api/cms/ad")
public class ApiAdController {

    @Autowired
    private AdService adService;
    @Autowired
    private RedisTemplate redisTemplate;


    @ApiOperation("根据Id查询广告")
    @GetMapping("list/{adTypeId}")
    public R selectAdByAdTypeId(@PathVariable String adTypeId){
        List<Ad> ads = adService.selectAdTypeById(adTypeId);
        return R.ok().data("items",ads);
    }

    @PostMapping("save-test")
    public R saveAd(@RequestBody Ad ad){
        redisTemplate.opsForValue().set("ad", ad);
        return R.ok();
    }



}

